% 2021.10.14
% HW2
% size(out.x1.Data)
close all;
clc;
clear;
% open_system('HW2_SLX')
result_sim = sim('HW2_SLX');
x1 = result_sim.x1.Data;
x2 = result_sim.x2.Data;
x3 = result_sim.x3.Data;
x_all = [x1 x2 x3];
xg = result_sim.xg.Data;

% 20 averages，见Welch方法，https://www.jianshu.com/p/bbd3975e594f
N = 20;

% []默认50%overlap
% 见MATLAB文档cpsd-Input Arguments-noverlap-
% "If you specify noverlap as empty..."
num_DFT = 1000;
% 1000，N点离散傅里叶变换NDFT(nfft)
figure('name', 'hanning')
cpsd(x_all, xg, hanning(N), [], 1000);
legend('cpsd_{x_1}_{x_g}', 'cpsd_{x_2}_{x_g}', 'cpsd_{x_3}_{x_g}')

figure('name', 'boxcar')
cpsd(x_all, xg, boxcar(N), [], 1000)
legend('cpsd_{x_1}_{x_g}', 'cpsd_{x_2}_{x_g}', 'cpsd_{x_3}_{x_g}')

